﻿
Partial Class Interfaz_frmAdminClientes
    Inherits System.Web.UI.Page
    Dim CL As New Logica.ModuloAdministracion.ControladorLogica

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.TxtRut.Attributes.Add("Onblur", "validarRut(this);")
            CL = Logica.ModuloAdministracion.ControladorLogica.getInstance
            If CL.visibilidadesFormsInternos("Administracion", Session("user").ToString) = False Then
                Response.Redirect("Index.aspx")
            End If
        Catch ex As Exception
            Me.Mensaje(ex.ToString)
        End Try
    End Sub

#Region "Botones"
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        InsertarProveedor()
        Limpiar()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Limpiar()
    End Sub
#End Region
    
#Region "funcionalidades"

    Public Sub Mensaje(ByVal msg As String)
        Dim alertScript As String = "<script language=JavaScript runat=server>"
        alertScript &= "alert('" & msg & "');"
        alertScript &= "</script>"
        ClientScript.RegisterClientScriptBlock(Page.GetType(), "clientScrip", alertScript)
    End Sub

    Private Sub Limpiar()
        TxtRut.Text = String.Empty
        TxTcompañia.Text = String.Empty
        TxtContacto.Text = String.Empty
        TxtTelefono.Text = String.Empty
        TxtEmail1.Text = String.Empty
        TxtEmail2.Text = String.Empty
        TxtGiro.Text = String.Empty
        TxtDireccion.Text = String.Empty
        TxtRegion.Text = String.Empty
        TxtCiudad.Text = String.Empty
        TxtFax.Text = String.Empty
        TxtComuna.Text = String.Empty
    End Sub

    Private Sub InsertarProveedor()
        Try
            Dim rut As String = Me.TxtRut.Text
            Dim compañia As String = Me.TxTcompañia.Text
            Dim contacto As String = Me.TxtContacto.Text
            Dim telefono As String = Me.TxtTelefono.Text
            Dim email As String = Me.TxtEmail1.Text + "@" + Me.TxtEmail2.Text
            Dim giro As String = Me.TxtGiro.Text
            Dim direccion As String = Me.TxtDireccion.Text
            Dim region As String = Me.TxtRegion.Text
            Dim ciudad As String = Me.TxtCiudad.Text
            Dim fax As String = Me.TxtFax.Text
            Dim comuna As String = Me.TxtComuna.Text
            Dim cliente As Cliente
            Dim proveedor As Proveedor

            If rut <> "" And compañia <> "" And contacto <> "" And telefono <> "" And email <> "" And giro <> "" And _
               direccion <> "" And region <> "" And ciudad <> "" And fax <> "" And comuna <> "" Then
                cliente = New Cliente(rut, compañia, direccion, giro, telefono, comuna, region, contacto, ciudad, fax, email, 0)

                CL.InsertarCliente(cliente)

                If Me.RBverifica.Checked = True Then
                    proveedor = New Proveedor(rut, compañia, direccion, giro, telefono, comuna, region, contacto, ciudad, fax, email)
                    CL.InsertarProveedor(proveedor)
                End If

                Me.Mensaje("Los datos han sido ingresados exitosamente")

            Else
                Me.Mensaje("Debe Rellenar todos los campos para ingresar un cliente ")
            End If
        Catch ex As Exception
            Me.Mensaje(ex.ToString)
        End Try
    End Sub
#End Region

   
End Class
